package com.gg.hj.controller;

import com.gg.common.pojo.SysMenus;
import com.gg.common.pojo.SysRoles;
import com.gg.common.pojo.SysUsers;
import com.gg.hj.search.SysRolesSearch;
import com.gg.hj.service.SysRolesService;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Controller
public class SysRolesController {
    @Resource
    private SysRolesService sysRolesService;

    //TODO 查询所有角
    @ResponseBody
    @RequestMapping("/queryRoleAll.action")
    public SysRolesSearch<SysRoles> queryRoleAll(@RequestBody SysRolesSearch<SysRoles> sysRolesSearch) throws Exception {
        return this.sysRolesService.queryRoleAllService(sysRolesSearch);
    }

   //TODO 当前登入账号查询角色具有菜单
    @ResponseBody
    @RequestMapping("/searchQueryUserIdMenu.action")
    public List<SysMenus> searchQueryUserIdMenu() throws Exception {
        SysUsers user = (SysUsers) SecurityUtils.getSubject().getSession().getAttribute("user");
        return this.sysRolesService.searchQueryUserIdMenuService(user.getId());
    }

    // TODO 查询角色 角色具有的菜单 授权菜单
    @ResponseBody
    @RequestMapping("/searchQueryByIdMenu.action")
    public SysRolesSearch<SysMenus> searchQueryByIdMenu(int id) throws Exception {
        return this.sysRolesService.searchQueryByIdMenuService(id);
    };
    //TODO 授权 或 回收 菜单
    @ResponseBody
    @RequestMapping("/AuthorizeOrRecycleMenus.action")
    public int AuthorizeOrRecycleMenus(int id,int[] check,int[] nocheck) throws Exception {
        return this.sysRolesService.AuthorizeOrRecycleMenusService(id,check,nocheck);
    };
    //TODO 新增角色
    @ResponseBody
    @RequestMapping("/saveRole.action")
    public int saveRole(@RequestBody SysRoles sysRoles) throws Exception {
        return this.sysRolesService.saveRoleService(sysRoles);
    };
}
